package cn.kuaida.oop;

import java.util.Random;

public class Game {
    private Player player;

    public Game() {
    }

    public Game(Player player) {
        setPlayer(player);
    }

    public Player getPlayer() {
        return player;
    }

    public void setPlayer(Player player) {
        this.player = player;
    }


    public String printStr(){
        int strLength=LevelParam.levels[player.getLevelNo()-1].getStrLength();
        StringBuffer buffer=new StringBuffer();
        Random random=new Random();
        for(int i=0;i<strLength;i++)
        {
            int rand=random.nextInt(strLength);
            switch(rand)
            {
                case 0:
                    buffer.append("w");
                    break;
                case 1:
                    buffer.append("a");
                    break;
                case 2:
                    buffer.append("s");
                    break;
                case 3:
                    buffer.append("d");
                    break;
                case 4:
                    buffer.append("z");
                    break;
                case 5:
                    buffer.append("f");
                    break;

            }
        }
        System.out.println(buffer);
        return buffer.toString();

    }
    public void printResult(String out,String in){
        boolean flag;
        if(out.equals(in))
        {
            flag=true;
        }
        else
        {
            flag=false;
        }
        if(flag)
        {
            long currentTime=System.currentTimeMillis();
            if((currentTime-player.getStartTime())/1000>
                    LevelParam.levels[player.getLevelNo()-1].getTimeLimit())
            {
                System.out.println("您的输入太慢了，已经超时，退出！");
                System.exit(1);
            }
            else
            {
                player.setCurrScore(player.getCurrScore()+
                        LevelParam.levels[player.getLevelNo()-1].getPerScore());
                player.setElapsedTime((int)((currentTime-player.getStartTime())/1000));
                System.out.println("输入正确，您的级别"+player.getLevelNo()+"，您的积分"
                        +player.getCurrScore()+",已用时间"+player.getElapsedTime()+"秒");
                int score=LevelParam.levels[player.getLevelNo()-1].getPerScore()
                        *LevelParam.levels[player.getLevelNo()-1].getStrTimes();
                if(player.getCurrScore()==score)
                {
                    System.out.println("闯关成功");
                    return;
                }
                int scoreLast = 0;
                if(player.getLevelNo()==6)
                {
                    scoreLast=LevelParam.levels[player.getLevelNo()-1].getPerScore()
                            *LevelParam.levels[player.getLevelNo()-1].getStrTimes();
                }

                if(player.getCurrScore()==scoreLast)
                {
                    System.out.println("恭喜通关！");
                    System.exit(0);
                }

            }
        }
        else
        {
            System.out.println("输入错误，退出！");
            System.exit(0);
        }

    }
}